package com.kscrm.web.controller.web;

import java.util.List;

import com.kscrm.common.utils.SecurityUtils;
import com.kscrm.web.domain.FollowUp;
import com.kscrm.web.service.IFollowUpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kscrm.common.annotation.Log;
import com.kscrm.common.core.controller.BaseController;
import com.kscrm.common.core.domain.AjaxResult;
import com.kscrm.common.enums.BusinessType;
import com.kscrm.common.core.page.TableDataInfo;

/**
 * 客户跟进记录Controller
 *
 * @author Dhq
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/web/followUp")
public class FollowUpController extends BaseController {
    @Autowired
    private IFollowUpService followUpService;

    /**
     * 查询客户跟进记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FollowUp followUp) {
        startPage();
        if (SecurityUtils.hasRole("channel") || SecurityUtils.hasRole("teacher")) {
            followUp.setUserId(SecurityUtils.getUserId());
        } else {
            followUp.setUserId(-1L);
        }

        List<FollowUp> list = followUpService.selectFollowUpList(followUp);
        return getDataTable(list);
    }


    /**
     * 获取客户跟进记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(followUpService.selectFollowUpById(id));
    }

    /**
     * 新增客户跟进记录
     */
    @Log(title = "客户跟进记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FollowUp followUp) {
        return toAjax(followUpService.insertFollowUp(followUp));
    }

    /**
     * 修改客户跟进记录
     */
    @Log(title = "客户跟进记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FollowUp followUp) {
        return toAjax(followUpService.updateFollowUp(followUp));
    }

    /**

     * 删除客户跟进记录
     */
    @Log(title = "客户跟进记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(followUpService.deleteFollowUpByIds(ids));
    }
}
